﻿using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.TeamFoundation.VersionControl.Client;

namespace TFSTools.TFSLibrary.VersionControl
{
    public sealed class TFSPendingSet : TFSServerEntity
    {
        private PendingSet serverPendingSet;

        internal TFSPendingSet(ITFSConnection connection, PendingSet pendingSet)
            : base(connection)
        {
            this.serverPendingSet = pendingSet;
        }

        public string OwnerName { get { return this.serverPendingSet.OwnerName; } }

        public string Name { get { return this.serverPendingSet.Name; } }

        public string Computer { get { return this.serverPendingSet.Computer; } }

        public TFSPendingChangeCollection PendingChanges
        {
            get
            {
                var pendingChanges = TFSPendingChangeCollection.Create(this.Connection, this.serverPendingSet.PendingChanges, this);
                return pendingChanges;
            }
        }

        public TFSWorkspace GetWorkSpace()
        {
            var workspace = Connection.VersionControl.Service.GetWorkspace(this.serverPendingSet.Name, this.serverPendingSet.OwnerName);
            return new TFSWorkspace(this.Connection, workspace);
        }
    }

    public sealed class TFSPendingSetCollection : TFSServerEntityCollection<TFSPendingSet>
    {
        public TFSPendingSetCollection(ITFSConnection connection)
            : base(connection)
        {
        }

        public TFSPendingSetCollection(ITFSConnection connection, IList<TFSPendingSet> list)
            : base(connection, list)
        {
        }

        public TFSPendingSetCollection(ITFSConnection connection, int capacity)
            : base(connection, capacity)
        {
        }

        internal static TFSPendingSetCollection Create(ITFSConnection connection, PendingSet[] sets)
        {
            var list = new List<TFSPendingSet>(sets.Length);

            foreach (var set in sets)
            {
                list.Add(new TFSPendingSet(connection, set));
            }

            return new TFSPendingSetCollection(connection, list);
        }
    }
}
